<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/6/1
 * Time: 11:04
 */
namespace app\admin\controller;

use app\admin\model\ShopTypeModel;

class ShopType extends BaseController
{
    public function __construct()
    {
        parent:: __construct();
        $this->shoptype = new ShopTypeModel();
    }
    //商铺类型显示
    public function index(){
        $list = $this->shoptype->index();
        $page = $list->render();
        $count = count($list);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('count',$count);
        return view('shoptype/index');
    }
    //商铺类型添加
    public function add(){
        if(request()->isAjax())
        {
            $res = $this->shoptype->add();
            if($res)
            {
                return ['code'=>'1','message'=>'添加成功'];
            }else{
                return ['code'=>'0','message'=>'添加失败'];
            }
        }
        return view('shoptype/add');
    }
    //商铺类型修改
    public function edit()
    {
        if(request()->isAjax())
        {
            $res = $this->shoptype->edit();
            if($res)
            {
                return ['code'=>'1','message'=>'修改成功'];
            }else{
                return ['code'=>'0','message'=>'修改失败'];
            }
        }
        $id = input('id');
        $res = $this->shoptype->getOneId($id);
        $this->assign('data',$res);
        return view('shoptype/edit');
    }
    //商铺类型删除
    public function del()
    {
        $res = $this->shoptype->del();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
}